package selcoursesys.action;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;
import selcoursesys.service.AdminService;
import selcoursesys.service.impl.AdminServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Lpbdz on 2017/4/11.
 */
public class AdminAction extends ActionSupport {
    //统计选课情况
    public String showSelectSitu() throws Exception{
        /**
         *  Get 选课信息
         *  Get
         **/
        HttpServletRequest request = ServletActionContext.getRequest();
        String admin=request.getParameter("admin");

        AdminService adminService=new AdminServiceImpl();
        if(adminService.showSelectSitu()==true){
            return "go_to_admin";
        }else{
            return ERROR;
        }
    }
    //显示选课细节
    public String showDetails() throws Exception{
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session;
        session=request.getSession();
        String cid=request.getParameter("courseid");
        session.setAttribute("courseid",cid);
        AdminService adminService=new AdminServiceImpl();
        if(adminService.showDeatil(cid)==true){
            return "go_to_detail";
        }
        return ERROR;
    }

    //根据课程名进行查找
    public String searchCourseName() throws  Exception{
        HttpServletRequest request = ServletActionContext.getRequest();
        String keyword=request.getParameter("keyword");
        String s1=new String(keyword.getBytes("ISO-8859-1"),"utf-8");
        keyword=s1;
        AdminService adminService=new AdminServiceImpl();
        if(adminService.searchCourseName(keyword)==true){
            return "go_to_admin";
        }else{
            return ERROR;
        }
    }
    //管理员搜索选课学生信息
    public String  searchSelectName() throws  Exception{
        HttpServletRequest request = ServletActionContext.getRequest();
        String keyword=request.getParameter("keyword");
        String s1=new String(keyword.getBytes("ISO-8859-1"),"utf-8");
        keyword=s1;
        String courseid=request.getParameter("courseid");
        AdminService adminService=new AdminServiceImpl();
        if(adminService.searchSelectInfo(keyword,courseid)==true){
            return "go_to_detail";
        }else{
            return ERROR;
        }
    }
}
